package com.krtech.wecard.module.farmhouse.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.krtech.wecard.framework.security.Inner;
import com.krtech.wecard.module.farmhouse.entity.FarmHouseArtisanManage;
import com.krtech.wecard.module.farmhouse.service.FarmHouseArtisanManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/artisanManage")
@Slf4j
@Api(value = "农房系统-工匠管理")
public class FarmHouseArtisanManageController {

    @Autowired
    private FarmHouseArtisanManageService artisanManageService;

    @PostMapping("/save")
    @ApiOperation(value = "save")
    public boolean backAdd(@RequestBody FarmHouseArtisanManage cdkMode) {
        cdkMode.setCreateTime(new Date());
        return artisanManageService.save(cdkMode);
    }

    @PostMapping("/updateById")
    @ApiOperation(value = "updateById")
    public boolean updateById(@RequestBody FarmHouseArtisanManage cdkMode) {
        return artisanManageService.updateById(cdkMode);
    }

    @GetMapping("/page")
    @ApiOperation(value = "page")
    public Page<FarmHouseArtisanManage> page(Page<FarmHouseArtisanManage> page, String keyword) {
        QueryWrapper<FarmHouseArtisanManage> wrapper = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(keyword)){
            wrapper.like(FarmHouseArtisanManage.COL_ARTISAN_NAME,keyword);
        }
        return artisanManageService.page(page,wrapper);
    }

    @GetMapping("/deleteById")
    @ApiOperation(value = "deleteById")
    public boolean page(Integer id){
        return artisanManageService.removeById(id);
    }
}
